package advanced.practice._1012;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);

        int NC=sc.nextInt();
        List<Long> coupons=new ArrayList<>();
        for(int i=0;i<NC;i++){
            coupons.add(sc.nextLong());
        }
        int NP=sc.nextInt();
        List<Long> products=new ArrayList<>();
        for(int i=0;i<NP;i++){
            products.add(sc.nextLong());
        }

        Collections.sort(coupons);
        Collections.sort(products);

        int m=0;
        int n=NP-1;

        long sum=0;
        for(int i=0;i<NC&&m<NP-1;i++){
            long coupon=coupons.get(i);
            if(coupon>0){
                break;
            }
            long product=products.get(m);
            if(product>0){
                break;
            }
            m++;
            sum+=coupon*product;
        }

        for(int i=NC-1;i>=0&&n>=m;i--){
            long coupon=coupons.get(i);
            long product=0;
            if(coupon<0){
                break;
            }
            product=products.get(n);
            if(product<0){
                break;
            }
            n--;
            sum+=coupon*product;
        }

        System.out.println(sum);
    }
}
